<?php 
$url = "http://www.shuaigeshe.com/uploads/allimg/150224/2009394960-0.jpg"; 
$url = explode('/', $url);
$index = $url[0].'//'.$url[2];
$name = $url[count($url) - 1];
$pre = '/([jpg|png|gif])/';
preg_match_all($pre, 'subject', $matches);

$filename = 'curl.gif'; 
getImg($url, $filename); 
function getImg($url = "", $filename = "") { 
	if(is_dir(basename($filename))) { 
		echo "The Dir was not exits"; 
		return false; 
	} 
	$url = preg_replace( '/(?:^[\'"]+|[\'"\/]+$)/', '', $url ); 
	$hander = curl_init(); 
	$fp = fopen($filename,'wb'); 
	curl_setopt($hander,CURLOPT_URL,$url); 
	curl_setopt($hander,CURLOPT_FILE,$fp); 
	curl_setopt($hander,CURLOPT_HEADER,1); 
	curl_setopt($hander,CURLOPT_FOLLOWLOCATION,1); 
	curl_setopt($hander,CURLOPT_TIMEOUT,60); 
	curl_exec($hander); 
	curl_close($hander); 
	fclose($fp); 
	return true; 
} 
?> 